package com.ruoyi.system.telManage.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.phone.domain.TelManageNew;
import com.ruoyi.system.phone.service.ITelManageNewService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.telManage.mapper.TelManageHistoryMapper;
import com.ruoyi.system.telManage.domain.TelManageHistory;
import com.ruoyi.system.telManage.service.ITelManageHistoryService;
import org.springframework.util.StringUtils;

/**
 * 手机操作记录Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Service
public class TelManageHistoryServiceImpl implements ITelManageHistoryService {
    @Autowired
    private TelManageHistoryMapper telManageHistoryMapper;

    @Autowired
    private ITelManageNewService telManageNewService
            ;

    /**
     * 查询手机操作记录
     *
     * @param id 手机操作记录主键
     * @return 手机操作记录
     */
    @Override
    public TelManageHistory selectTelManageHistoryById(Long id) {
        return telManageHistoryMapper.selectTelManageHistoryById(id);
    }

    /**
     * 查询手机操作记录列表
     *
     * @param telManageHistory 手机操作记录
     * @return 手机操作记录
     */
    @Override
    public List<TelManageHistory> selectTelManageHistoryList(TelManageHistory telManageHistory) {
        return telManageHistoryMapper.selectTelManageHistoryList(telManageHistory);
    }

    /**
     * 新增手机操作记录
     *
     * @param telManageHistory 手机操作记录
     * @return 结果
     */
    @Override
    public int insertTelManageHistory(TelManageHistory telManageHistory) {
        telManageHistory.setCreateTime(DateUtils.getNowDate());
        return telManageHistoryMapper.insertTelManageHistory(telManageHistory);
    }

    /**
     * 添加操作记录
     *
     * @param
     * @return 结果
     */
    @Override
    public int addOperator(Map<String, Object> params) {
        TelManageHistory history = new TelManageHistory();
        history.setCreateId(MapUtils.getLong(params, "userId"));
        history.setOperator(MapUtils.getString(params, "operator"));
        history.setStatus(MapUtils.getString(params, "status"));
        String reason = MapUtils.getString(params, "reason");
        String img = MapUtils.getString(params, "img");
        if (StringUtils.isEmpty(reason)) {
            Long telId = MapUtils.getLong(params, "telId");
            TelManageNew manage = telManageNewService.selectTelManageNewById(telId);
            reason = manage.getTel();
        }
        reason="手机号 :"+reason;
        if (!StringUtils.isEmpty(MapUtils.getString(params, "bindAccount"))){
            reason += " 绑定账号:"+MapUtils.getString(params, "bindAccount");
        }
        if (!StringUtils.isEmpty(MapUtils.getString(params, "useTime"))){
            reason += " 间隔天数："+MapUtils.getString(params, "useTime");
        }
        history.setImg(img);
        history.setReason(reason);
        history.setTelId(MapUtils.getLong(params, "telId"));
        history.setCreateTime(DateUtils.getNowDate());
        return telManageHistoryMapper.insertTelManageHistory(history);
    }

    /**
     * 修改手机操作记录
     *
     * @param telManageHistory 手机操作记录
     * @return 结果
     */
    @Override
    public int updateTelManageHistory(TelManageHistory telManageHistory) {
        return telManageHistoryMapper.updateTelManageHistory(telManageHistory);
    }

    /**
     * 批量删除手机操作记录
     *
     * @param ids 需要删除的手机操作记录主键
     * @return 结果
     */
    @Override
    public int deleteTelManageHistoryByIds(Long[] ids) {
        return telManageHistoryMapper.deleteTelManageHistoryByIds(ids);
    }

    /**
     * 删除手机操作记录信息
     *
     * @param id 手机操作记录主键
     * @return 结果
     */
    @Override
    public int deleteTelManageHistoryById(Long id) {
        return telManageHistoryMapper.deleteTelManageHistoryById(id);
    }
}
